local Class = require('lua.lang.Class')
local Varargs = require('lua.vm.Varargs')

--- @class PairVarargs : Varargs
--- @field v1 LuaValue
--- @field v2 Varargs
local PairVarargs = Class {
	__extends = Varargs
}

--- @param v1 LuaValue
--- @param v2 Varargs
--- @return PairVarargs
function PairVarargs:new(v1, v2)
	--- @type PairVarargs
	local o = {}
	o.v1 = v1
	o.v2 = v2
	return setmetatable(o, PairVarargs)
end

--- @param i number
--- @return LuaValue
function PairVarargs:arg(i)
	return i == 1 and self.v1 or self.v2:arg(i - 1)
end

--- @return number
function PairVarargs:narg()
	return 1 + self.v2:narg()
end

--- @return LuaValue
function PairVarargs:arg1()
	return self.v1
end

--- @return Varargs
function PairVarargs:subArgs(start)
	if start == 1 then
		return self
	elseif start == 2 then
		return self.v2
	elseif start > 2 then
		return self.v2:subArgs(start - 1)
	end
	return self:argError(1, 'start must be > 0')
end

return PairVarargs